package com.i8office.android.zhihuixinwu.module.model;

import com.cyan.tools.callback.RequestCallback;
import com.cyan.tools.callback.SimpleCallback;
import com.i8office.android.zhihuixinwu.app.App;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.bean.People;
import com.i8office.android.zhihuixinwu.bean.Result;
import com.i8office.android.zhihuixinwu.bean.SendInfo;
import com.i8office.android.zhihuixinwu.module.contract.StaffContract;
import com.i8office.android.zhihuixinwu.util.OfficeSubscriber;

import java.util.ArrayList;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/7/8.
 */

public class StaffModel implements StaffContract.Model {
    @Override
    public Disposable getSendInfo(final RequestCallback<SendInfo> callback, Map<String,String> map) {
        return App.getComponent().getAPIService().getSendInfo(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Result<SendInfo>>(callback){
            @Override
            public void onNext(Result<SendInfo> o) {
                callback.requestSuccess(o.getData());
            }
        });
    }

    @Override
    public Disposable searchPeople(RequestCallback<ArrayList<People>> callback, Map<String, String> map) {
        return App.getComponent().getAPIService().searchPeople(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<ArrayList<People>>(callback));
    }

    @Override
    public Disposable checkBeforeSubmit(SimpleCallback<Code> callback, Map<String, String> map) {
        return App.getComponent().getAPIService().checkFieldsBeforeSubmit(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable send(SimpleCallback<Code> callback, Map<String, String> map) {
        return App.getComponent().getAPIService().send(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable open(SimpleCallback<String> callback, Map<String, String> map) {
        return App.getComponent().getAPIService().open(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<String>(callback));
    }

    @Override
    public Disposable sendNotification(SimpleCallback<String> callback, Map<String, String> map) {
        return App.getComponent().getAPIService().sendNotification(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<String>(callback));
    }
}
